
cap cd "/Users/kevincroke/Dropbox/UG Uwezo/Dataverse/raw_data/UNPS"

set more off

/*
2009/10 Uganda National Panel Survey
This code is to replicate Supplementary Information Table S4 and Figure 1
*/

use GSEC1, clear
sort HHID 
merge 1:m HHID using GSEC2 
drop _merge
destring comm, replace

*label demographic variables 
rename h2q3 gender
gen female= (gender==2)
rename h2q4 hh_position
gen non_nuclear= (hh_position>3)
rename h2q8 age
rename h2q5 months_hh
rename h2q6 reason_move

*generate indicators for individuals who have moved/left hh for varying lengths of time 
gen any_move= (months_hh<12)
gen three_mo_move= (months_hh<=9)
gen six_mo_move= (months_hh<=6)

*merge with education section
sort HHID PID
merge  1:1 PID using GSEC3 
drop _merge 
merge  1:1 PID using GSEC4
drop _merge 

*generate literacy, school attainment variables
rename h4q4 literacy
gen read_and_write= (literacy==4)

*prepare for merge with poverty/consumption data
destring HHID, replace
sort HHID

merge m:1 HHID using poverty.dta
gen rural= (urban==0) if urban!=. 

*************
*Table S4
************

cap cd "/Users/kevincroke/Dropbox/UG Uwezo/Dataverse"

*Table S4 Panel A: evidence of selection on academic skills (reading/writing) into migration
reg any_move read_and_write i.age, r cluster(comm)
estimates store reg1
reg any_move read_and_write i.age poor, r cluster(comm)
estimates store reg2
reg any_move read_and_write i.age poor female non_nuclear rural, r cluster(comm)
estimates store reg3
reg any_move read_and_write i.age poor female non_nuclear rural i.district, r cluster(comm)
estimates store reg4
esttab reg1 reg2 reg3 reg4, se starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant)  replace title("Table S4 Panel A") keep(read_and_write)


*Table S4 Panel A: evidence of selection with continuous literacy, under16 sample
reg any_move literacy i.age if age>=6 &  age<=16, r cluster(comm)
estimates store reg1
reg any_move literacy i.age poor if age>=6 & age<=16, r cluster(comm)
estimates store reg2
reg any_move literacy i.age poor female non_nuclear rural if age>=6 & age<=16, r cluster(comm)
estimates store reg3
reg any_move literacy i.age poor female non_nuclear rural i.district if age>=6 & age<=16, r cluster(comm)
estimates store reg4
esttab reg1 reg2 reg3 reg4, se starlevels(* .1 ** .05 *** .01) varlabels(_cons Constant) eqlabels(none)  replace title("Table S4 Panel B") keep(literacy)

**********
**Figure 1
**********


graph bar any_move if age>=6 & age<=16, over(age) ytitle("% spending >=1 month away by age")  scheme(sj)
graph save Graph "1month.gph", replace


graph bar three_mo_move if age>=6 & age<=16, over(age) ytitle("% spending >=3 months away by age")  scheme(sj) 
graph save Graph "3month.gph", replace


graph bar six_mo_move if age>=6 & age<=16, over(age) ytitle("% spending >=6 month away by age")  scheme(sj)
graph save Graph "6month.gph", replace


gr combine "1month.gph" "3month.gph" "6month.gph", ///
rows(2) cols(2) subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))

